--[[
    NuckPluck - An android game for learning the Thai alphabet
    Copyright (C) 2013 Nathan Kieffer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Contact: nathankieffer@gmail.com
--]]

local storyboard = require("storyboard")
local widget = require("widget")
local scene = storyboard.newScene()
local levels = require("levels")
local function renderRow(event)
   local row = event.row
   local level = row.params
   print(level.map)
   local chars = ""
   for i,char in pairs(level.data) do
      chars = chars.." "..char.char
   end

   local label = display.newText{ parent=row, 
				  text=chars, 
				  x=0, y=0,
				  font=native.systemFont, 
				  fontSize=24,
				  align="left"}
   label.anchorX=0
   label.anchorY=0
   label:setFillColor(0)
end

local function touchRow(event)
   print(event.target.params)
   storyboard.gotoScene("gameBoard",{params=event.target.params})
end
function scene:createScene(event)
   print("CREATE")
   local group =  self.view
   local levelMenu = widget.newTableView{ width=display.contentWidth,
					  height=display.contentHeight,
					  top=0,
					  onRowRender=renderRow,
					  onRowTouch = touchRow
   }
   for i=1,#levels do
      local level = levels[i]
      levelMenu:insertRow{ rowHeight=display.contentHeight * 0.1,
			   rowColor = {1,1,1,.5},
			   params = level,
      }
   end
   group:insert(levelMenu)
end

function scene:enterScene(event)
   local group = self.view

end

function scene:exitScene(event)
   local group = self.view

end

scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)





return scene